//导入express
const express = require("express");
//实例化路由对象
const apiRouter = express.Router();
//引入addUser.js
const addUser=require("../service/addUser");
//引入users.js
const users=require("../model/users");
//引入userLOgin.js
const userLogin=require("../service/userLogin");

//获取首页文章数据
apiRouter.get("/articleList",(req,res,next)=>{

})
//获取首页推荐作者
apiRouter.get("/authorsList",(req,res,next)=>{
    //接收参数
    let classify = req.query.classify;
})
//用户登录
apiRouter.post("/userLogin",(req,res,next)=>{
    //接收参数
    let body = req.body;
    let userName = body.userName;
    let userPassword = body.userPassword;

    //参数转json
    users.userName=userName;
    users.userPassword=userPassword;
    //调用登录的方法
    userLogin(users,res);
})

//注册路由请求
apiRouter.get("/",(req,res,next)=>{
    //接收传进来的参数
    let body = req.body;
    let userName = body.userName;
    let arr = req.body;
    let desc = body.desc;

    userName.userId=new Date().getTime();
    users.userName=userName;
    users.userPassword=userPassword;
    users.desc=desc;
    users.createTime=new Date();
    //调用service添加的方法
    addUser(users,res);
})
//加载个人文章列表, 参数为个人id
apiRouter.get("/myArticleList",(req,res,next)=>{
    //接收参数
    let userId = req.query.userId;
})

//新增文章
apiRouter.post("/addArticle",(req,res,next)=>{
    //接收参数
    let body =req.body;
    let title = body.title;
    let content=body.content;

})
   
//导出
module.exports = apiRouter;